<template>
  <div class="wrapper">
    <div style="height:200px">
      <FormPanel
        ref="from"
        :list="formList"
        formType="show"
        labelWidth="100"
        :cols="3"
        :isSubmitBtn="false"
        :collapse="false"
      />

<!--      @formChange="formChangeHandle2"-->
    </div>
    <BreakSpace label="SAP承运单包装信息" :containerStyle="{ marginBottom: '15px' }" />
    <FilterTable
      ref="mainTable"
      :columns="tableColumns"
      columnsRef="aduitOrder"
      :datakey="'records'"
      selectionType="single"
      :isSelectColumn=false
      :dataSource="dataSource"
      :onEnterEvent="onEnterEvent"
      :onColumnsChange="columns => (this.tableColumns = columns)"
    >
    </FilterTable>
    <BreakSpace label="发运单信息" :containerStyle="{ marginBottom: '15px' }" />
    <FilterTable
      ref="mainTable1"
      :columns="tableColumns1"
      columnsRef="aduitOrder"
      selectionType="single"
      :isSelectColumn=false
      :dataSource="dataSource1"
      :onEnterEvent="onEnterEventto"
      :onColumnsChange="columns => (this.tableColumns1 = columns)"
    >
    </FilterTable>
    <BreakSpace label="交货清单列表" :containerStyle="{ marginBottom: '15px' }" />
    <FilterTable
      ref="mainTable2"
      :columns="tableColumns2"
      columnsRef="aduitOrder"
      :datakey="'records'"
      selectionType="single"
      :dataSource="dataSource2"
      :isSelectColumn=false
      :onColumnsChange="columns => (this.tableColumns2 = columns)"
    >
    </FilterTable>
    <div class="dialogBottmView">
      <el-button @click="closeDialogTop">返 回</el-button>
    </div>

  </div>
</template>
<script>
import { partbuyStockInItemOEM,auditOrder,aduitPocess } from '@/api/partsmanage/carrierTrace/query';
import { dictionary } from '@/utils/dictMixin';
import {ddlxArr, ddztArr, ddtblxArr,ddtshArr } from './constant';

export default {
  name: 'partBuyItems',
  props: {
    top: {
        type: Object,
        default: {},
        required: true
    }
  },
  mixins: [dictionary],
  data() {
    return {
      formList: this.createTopFilterList(),
      tableColumns: this.createTableColumns(),
      tableColumns1: this.createTableColumns1(),
      tableColumns2: this.createTableColumns2(),
      fetchParams: {},
      dataSource: [],
      dataSource1: [],
      dataSource2: [],
      visible: false,
      loading: false,

    };
  },
  created() {
    this.findBuyItems(this.top);
  },
  methods: {
    createTopFilterList() {
      return [
        {
          type: 'INPUT',
          label: '承运单号',
          fieldName: 'coNo',
          initialValue: '',
          disabled: true
        },
        {
          type: 'DATE',
          fieldName: 'coCreateDate',
          initialValue: '',
          label: '承运单日期',
          dateFormat: 'yyyy-MM-dd',
          disabled: true
        },
        {
          type: 'SELECT',
          label: '承运单状态',
          initialValue: '',
          fieldName:'CO_STATUS',
          itemList: [{ text: '已发运', value: '30141001' }, { text: '已到货', value: '30141002' }, { text: '已验收', value: '30141003' }],
          disabled: true
        },
        {
          type: 'INPUT',
          label: '服务站代码',
          fieldName: 'cpanyCode',
          initialValue: '',
          disabled: true
        },
        {
          type: 'INPUT',
          label: '服务站名称',
          fieldName: 'companyName',
          initialValue: '',
          disabled: true
        },
        {
          type: 'INPUT',
          label: '运费',
          fieldName: 'zcurr01',
          initialValue: '',
          disabled: true
        },
        {
          type: 'SELECT',
          label: '发运方式',
          fieldName: 'BTYSLX',
          itemList: [{ text: '普通', value: '30241001' }, { text: '快递', value: '30241002' }, { text: '其他', value: '30241003' }],
          initialValue: '',
          disabled: true
        },
        {
          type: 'DATE',
          fieldName: 'BSFYRQ',
          initialValue: '',
          label: '发运日期',
          dateFormat: 'yyyy-MM-dd',
          disabled: true
        },
        {
          type: 'INPUT',
          label: '快递单号',
          fieldName: 'tdlnr',
          initialValue: '',
          disabled: true
        },
        {
          type: 'INPUT',
          label: '承运商名称',
          initialValue: '',
          fieldName: 'coStoreName',
          placeholder: '请输入...',
          disabled: true
        },
        {
          type: 'INPUT',
          label: '承运联系人',
          initialValue: '',
          fieldName: 'ernam',
          placeholder: '请输入...',
          disabled: true
        },
        {
          type: 'INPUT',
          label: '联系电话',
          initialValue: '',
          fieldName: 'telph',
          placeholder: '请输入...',
          disabled: true
        },
        {
          type: 'INPUT',
          label: '总包装件数',
          sorter: true,
          fieldName: 'menge',
          precision: 2,
          filter: true,
          filterType: 'number'
        },
        {
          type: 'INPUT',
          label: '送货地址',
          initialValue: '',
          fieldName: 'thdz',
          placeholder: '请输入...',
          disabled: true
        },
        {
          type: 'TEXT_AREA',
          label: '备注',
          selfCols: 1,
          initialValue: '',
          maxlength: 1000,
          fieldName: 'remark',
          placeholder: '请输入...',
          disabled: true
        }
      ];
    },
    createTableColumns() {
      return [
        {
          title: '承运编号',
          width: 180,
          sorter: true,
          dataIndex: 'TKNUM',
          showOverflowTooltip: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '装运项目',
          width: 180,
          sorter: true,
          dataIndex: 'POSNR',
          showOverflowTooltip: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '车牌',
          sorter: true,
          dataIndex: 'CARNUM',
          filter: true,
        },
        {
          title: '包装种类',
          sorter: true,
          dataIndex: 'ZPACK',
          filter: true,
          render: props => {
            return <span>{this.createDictText(props.row.ZPACK, '3035')}</span>;
          }
        },
        {
          title: '件数',
          sorter: true,
          dataIndex: 'MENGE',
          filter: true
        },
        {
          title: '毛重',
          sorter: true,
          dataIndex: 'BRGEW',
          precision: 2,
          filter: true,
          filterType: 'number'
        },
       {
         title: '体积',
         sorter: true,
         dataIndex: 'VOLEH',
         precision: 2,
         filter: true,
         filterType: 'number'
       },
        {
          title: '付款方式',
          sorter: true,
          dataIndex: 'ZPAYTYPE',
          filter: true,
          filterType: 'number',
        },
        {
          title: '电话',
          sorter: true,
          dataIndex: 'TELPH',
          filter: true,
          filterType: 'number'
        },
        {
          title: '提货地址',
          sorter: true,
          dataIndex: 'THDZ',
          filter: true,
          filterType: 'number'
        },
        {
          title: '备注',
          sorter: true,
          dataIndex: 'ZTXT01',
          filter: true
        }
      ];
    },
    createTableColumns1() {
      return [
        {
          title: '交货单号',
          sorter: true,
          dataIndex: 'BSYSDH',
        },
        {
          title: '发货日期',
          sorter: true,
          dataIndex: 'BSFYRQ',
          dateFormat: 'yyyy-MM-dd',
        },
        {
          title: '收货单位',
          dataIndex: 'DEALER_NAME',
          sorter: true,
        },
        {
          title: '收货联系人',
          sorter: true,
          dataIndex: 'CONTACT_MAN',
        },
        {
          title: '收货联系电话',
          dataIndex: 'CONTACT_PHONE',
          sorter: true
        },
        {
          title: '用户地址',
          dataIndex: 'XXSHDZ',
          sorter: true,
        },
        {
          title: '到货日期',
          dataIndex: 'BSSCRQ',
          sorter: true,
          dateFormat: 'yyyy-MM-dd',
        },
        {
          title: '运输单位',
          dataIndex: 'WS_NAME',
          sorter: true,
        },
        {
          title: '联系人',
          dataIndex: 'WS_PERSON',
          sorter: true,
        },
        {
          title: '联系电话',
          dataIndex: 'WS_PHONE',
          sorter: true,
        },
        {
          title: '备注',
          dataIndex: 'WS_REMARK',
          sorter: true,
        },
      ];
    },

    createTableColumns2() {
      return [
        {
          title: '交货单号',
          width: 180,
          sorter: true,
          dataIndex: 'BSYSDH',
          showOverflowTooltip: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: 'SAP交货单',
          width: 180,
          sorter: true,
          dataIndex: 'BSJHDH',
          showOverflowTooltip: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '交货日期',
          dataIndex: 'BSSCRQ',
          filter: true,
          sorter: true,
          filterItems: ddtshArr,
          dictItems: ddtshArr,
          filterType: 'checkbox'
        },
        {
          title: '交货单状态',
          sorter: true,
          dataIndex: 'XSDJZT',
          filter: true,
          filterType: 'number',
          render: props => {
            return <span>{this.createDictText(props.row.XSDJZT, '3014')}</span>;
          }
        },
        {
          title: '备件编码',
          width: 180,
          sorter: true,
          dataIndex: 'BJXMBH',
          showOverflowTooltip: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '备件名称',
          width: 180,
          sorter: true,
          dataIndex: 'BJZWMC',
          showOverflowTooltip: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '单位',
          width: 180,
          sorter: true,
          dataIndex: 'BJDANW',
          showOverflowTooltip: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '交货数量',
          width: 180,
          sorter: true,
          dataIndex: 'BSFYSL',
          showOverflowTooltip: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '交货单价',
          width: 180,
          sorter: true,
          dataIndex: 'AUDIT_TIME6',
          render: props => {
            return <span>{this.comuput(props)}</span>;
          }
        },
        {
          title: '交货金额',
          dataIndex: 'BSFYJE',
          filter: true,
          sorter: true,
          filterItems: ddtshArr,
          dictItems: ddtshArr,
          filterType: 'checkbox'
        },
        {
          title: '备注',
          sorter: true,
          dataIndex: 'BSCYYY',
          filter: true,
          filterType: 'number'
        },
      ];
    },

    closeDialogTop(){
       this.$emit('cancel');
    },

    toDecimal(x) {
      var val = Number(x)
      if(!isNaN(parseFloat(val))) {
        val = val.toFixed(2);
      }
      return val;
    },

    onEnterEvent(row) {
      aduitPocess({ partOrderId: row.TKNUM }).then(res =>{
        if(res){
          this.$nextTick(() => this.dataSource1 = res.data)
        }else{
          this.dataSource1=[];
        }
      });
    },
    onEnterEventto(row){
      console.log(row);
      auditOrder({ partOrderId: row.BSYSDH }).then(res =>{
        if(res){
          console.log('this.form123 ============ :'+ JSON.stringify(res));
          this.$nextTick(() => this.dataSource2 = res.data)
        }else{
          this.dataSource2=[];
        }
      });
    },

    comuput(data){
      const lid= this.numDiv(data.row.BSFYJE,data.row.BSFYSL);
      return lid;
    },
    numDiv(num1, num2) {
      let c=num1/num2;
     return c.toString().match(new RegExp(/^\d+(?:\.\d{0,2})?/))
    },
    formChangeHandle2(val) {},
      findBuyItems(data) {
      this.formList.forEach(x => {
        x.initialValue = data[x.fieldName];
      });
      console.log("承运单号"+this.top.coNo);
      partbuyStockInItemOEM({ partOrderId: this.top.coNo }).then(res =>{
        if(res){
          this.dataSource = res.data;
        }else{
          this.dataSource=[];
        }
      });
      // console.log('this.form ============ :'+ JSON.stringify(res));
      // this.dataSource1 = res1.data;
      // let res2 = await aduitPocess({ partOrderId: this.top.coNo });
      // console.log('this.form ============ :'+ JSON.stringify(res));
      // this.dataSource2 = res2.data;
    }
  }
};
</script>
